package com.example.blogserver.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SuppressWarnings({"all"})
@Configuration
public class LoginConfig implements WebMvcConfigurer {

    @Autowired
    LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //配置拦截规则
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                //排除所有静态资源
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/editor.md/**")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/image/**")
                .excludePathPatterns("/photo/**")
                //排除无需登录即可操作的页面
                .excludePathPatterns("/blog_login.html")
                .excludePathPatterns("/blog_register.html")
                //排除接口
                .excludePathPatterns("/login/sub")
                .excludePathPatterns("/login/verifyCode")
                .excludePathPatterns("/register/sendEmailCode")
                .excludePathPatterns("/register/Registration");
    }
}
